package com.kayb.patterns.structural;

/**
 * 外观模式，也叫门面模式，主要是为了降低系统与系统之间类的耦合度而采取统一的类来管理多个类，从而隐藏内部子系统具体实现。
 * 实现：新建facade类，将多个类之间的生命周期交于Facade类管理
 * @author huangkaibin
 * @date 2018-08-28
 **/
public class Facade {

    interface Lifecycle {
        void start();
        void stop();
    }

    static class CPU implements Lifecycle{

        @Override
        public void start() {
            System.out.println("CPU start");
        }

        @Override
        public void stop() {
            System.out.println("CPU stop");
        }
    }

    static class Disk implements Lifecycle{

        @Override
        public void start() {
            System.out.println("Disk start");
        }

        @Override
        public void stop() {
            System.out.println("Disk stop");
        }
    }

    static class Memory implements Lifecycle{

        @Override
        public void start() {
            System.out.println("Memory start");
        }

        @Override
        public void stop() {
            System.out.println("Memory stop");
        }
    }

    static class Computer implements Lifecycle {
        private CPU cpu;
        private Memory memory;
        private Disk disk;

        public Computer() {
            this.cpu = new CPU();
            this.memory = new Memory();
            this.disk = new Disk();
        }


        @Override
        public void start() {
            cpu.start();
            memory.start();
            disk.start();
        }

        @Override
        public void stop() {
            cpu.stop();
            memory.stop();
            disk.stop();
        }
    }

    public static void main(String[] args) {
        Computer computer = new Computer();
        computer.start();
        computer.stop();
    }

}
